package com.CNMedical.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.CNMedical.common.annotation.Log;
import com.CNMedical.common.core.controller.BaseController;
import com.CNMedical.common.core.domain.AjaxResult;
import com.CNMedical.common.enums.BusinessType;
import com.CNMedical.system.domain.entity.AppletKnowledgeType;
import com.CNMedical.system.service.IAppletKnowledgeTypeService;
import com.CNMedical.common.utils.poi.ExcelUtil;
import com.CNMedical.common.core.page.TableDataInfo;

/**
 * 知识类型Controller
 * 
 * @author tang
 * @date 2023-03-28
 */
@RestController
@RequestMapping("/system/type")
public class AppletKnowledgeTypeController extends BaseController
{
    @Autowired
    private IAppletKnowledgeTypeService appletKnowledgeTypeService;

    /**
     * 查询知识类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppletKnowledgeType appletKnowledgeType)
    {
        startPage();
        List<AppletKnowledgeType> list = appletKnowledgeTypeService.selectAppletKnowledgeTypeList(appletKnowledgeType);
        return getDataTable(list);
    }

    /**
     * 导出知识类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:type:export')")
    @Log(title = "知识类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppletKnowledgeType appletKnowledgeType)
    {
        List<AppletKnowledgeType> list = appletKnowledgeTypeService.selectAppletKnowledgeTypeList(appletKnowledgeType);
        ExcelUtil<AppletKnowledgeType> util = new ExcelUtil<AppletKnowledgeType>(AppletKnowledgeType.class);
        util.exportExcel(response, list, "知识类型数据");
    }

    /**
     * 获取知识类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:type:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(appletKnowledgeTypeService.selectAppletKnowledgeTypeById(id));
    }

    /**
     * 新增知识类型
     */
    @PreAuthorize("@ss.hasPermi('system:type:add')")
    @Log(title = "知识类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppletKnowledgeType appletKnowledgeType)
    {
        return toAjax(appletKnowledgeTypeService.insertAppletKnowledgeType(appletKnowledgeType));
    }

    /**
     * 修改知识类型
     */
    @PreAuthorize("@ss.hasPermi('system:type:edit')")
    @Log(title = "知识类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppletKnowledgeType appletKnowledgeType)
    {
        return toAjax(appletKnowledgeTypeService.updateAppletKnowledgeType(appletKnowledgeType));
    }

    /**
     * 删除知识类型
     */
    @PreAuthorize("@ss.hasPermi('system:type:remove')")
    @Log(title = "知识类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(appletKnowledgeTypeService.deleteAppletKnowledgeTypeByIds(ids));
    }
}
